'use strict';

var extend = function (derived, base) {
    derived.prototype = Object.create(base.prototype);
    derived.prototype.constructor = derived;
    derived.base = base.prototype;

    if (base.prototype.constructor == Object.prototype.constructor) {
        base.prototype.constructor = base;
    }
};

var augment = function (to, from) {

    for (var methodName in from.prototype) {
        if (!to.prototype[methodName]) {
            to.prototype[methodName] = from.prototype[methodName];
        }
    }
};

exports.define = function (conf) {

    var construct = conf.construct || function () { };

    if (conf.base) {
        extend(construct, conf.base);
    }

    if (conf.mixins) {
        var i, len;
        for (i = 0, len = conf.mixins.length; i < len; ++i) {

            var mixin = conf.mixins[i];

            if (mixin) {
                augment(construct, mixin);
            }
        }
    }

    for (var key in conf) {
        if (key != 'construct'
                    && key != 'base'
                    && key != 'mixins') {
            construct.prototype[key] = conf[key];
        }
    }

    return construct;
};